package code20210930;

public class C223 {

	public static void main(String[] args) {
		//int ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2;
		//int ax1 = 0, ay1 = 0, ax2 = 0, ay2 = 0, bx1 = -1, by1 = -1, bx2 = 1, by2 = 1;
		//int ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -4, by1 = 3, bx2 = -3, by2 = 4;
		int ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -1, by1 = -1, bx2 = 1, by2 = 1;

		System.out.println(new C223().computeArea(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2));
	}
	public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
		int l = Math.abs((ax2 + ax1) - (bx2 + bx1)) - Math.abs(ax2 - ax1 + bx2 - bx1);
		int h = Math.abs((ay2 + ay1) - (by2 + by1)) - Math.abs(ay2 - ay1 + by2 - by1);
		int area = (ax2 - ax1)*(ay2 - ay1) + (bx2 - bx1)*(by2 - by1);
		//System.out.println(l+","+h+","+area);
		if(l<0 && h<0) {
			l = ax1<=bx1?(ax2<=bx2?ax2-bx1:bx2-bx1):(ax2<=bx2?ax2-ax1:bx2-ax1);
			h = ay1<=by1?(ay2<=by2?ay2-by1:by2-by1):(ay2<=by2?ay2-ay1:by2-ay1);
			//System.out.println(l+","+h+","+l*h);
			area -= l*h;
		}
		return area;
    }
}
